# -*- coding: utf-8 -*-
import logging

from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect
from pylons import url, config
from pylons.decorators import cache
from pylons.decorators.cache import beaker_cache
from repoze.what.plugins.pylonshq import ControllerProtector, ActionProtector
from repoze.what.predicates import in_all_groups, in_any_group
from pylons.decorators import jsonify
import json

from craneserver.lib.base import BaseController, render

log = logging.getLogger(__name__)

@ControllerProtector(in_any_group('Super User','HPC User', 'Web Hosting User', 'IaaS User'))
class AppController(BaseController):

    def index(self):
        return render('index.mako')
    def mobile(self):
        return render('mobileIndex.mako')
    def menu(self):
        identity = request.environ.get('repoze.who.identity')
        isadmin = 'Super User' in list(identity['groups'])
        if not isadmin:
            return render('user_menu.mako')
        else:
            return render('admin_menu.mako')
    def whoiam(self):
        return json.dumps({'userid': c.userid})
    def allsites(self):
    	sites = config.get('crane.sites').split(',')
    	return json.dumps({'allsites': sites})
        
